#!/usr/bin/env perl

use strict;
use 5.010;

printf "test\n";

my %hash = ("key1" => "amei", "key2" => "leo");
foreach my $keys (sort keys %hash)
{
    my $value = $hash{$keys};
    printf " $keys => $value \n";
    printf " $keys => $hash{$keys} \n";
}

printf "----\n";

my @array = %hash;
printf "@array \n";

my %new_hash = ("1", "2", "3", "4");

my $new_hash_count = scalar %new_hash;
printf "----\n";
printf "$new_hash_count \n";
printf "$new_hash{'1'}\n";
#printf "$new_hash{'2'}\n";
printf "$new_hash{'3'}\n";
#printf "$new_hash{'4'}\n";

my @new_hash_keys = keys %new_hash;
my @new_hash_value = values %new_hash;
my $new_hash_count = %new_hash;

printf "@new_hash_keys \n";
printf "@new_hash_value \n";
printf $new_hash_count . "\n";


while( my ($key, $value) = each %new_hash)
{
    printf "$key, $value\n";
}


foreach my $key (sort keys %new_hash)
{
    print "$new_hash{$key} \n";
}

# test exists:
if (exists($new_hash{'1'}))
{
    printf "key '1' exists\n";
}
else
{
    printf "key '1' doesn't exists\n";
}

if (exists($new_hash{'5'}))
{
    printf "key '5' exists\n";
}
else
{
    printf "key '5' doesn't exists\n";
}

# add new value
$new_hash{'5'} = '6';


if (exists($new_hash{'5'}))
{
    printf "key '5' exists\n";
}
else
{
    printf "key '5' doesn't exists\n";
}

# test delete
delete $new_hash{'5'};


if (exists($new_hash{'5'}))
{
    printf "key '5' exists\n";
}
else
{
    printf "key '5' doesn't exists\n";
}

# test copy
my %copy_hash = %new_hash;
foreach my $item (keys %copy_hash)
{
    printf "$item => $copy_hash{$item} \n";
}
